//
//  DataUtil.m
//  BTDemo
//
//  Created by iTrainer Golf on 19/9/14.
//  Copyright (c) 2014 Alvin. All rights reserved.
//

#import "DataUtil.h"

/*
*   Calculate a 16-bit CRC over the specified data buffer, that can be sent with
*   a command to validate the content
*
*   @param pBuff Pointer to the data buffer over which CRC will be calculated
*   @param length The length of the data to be CRC'd
*
*   @return 16-bit CRC value
*
*/
unsigned short CalcChecksum( void * pBuff, unsigned short length)
{
    unsigned short checkSum = 0;
    //unsigned short     i;
    int i;
    
    for (i = 0; i < length-2; i++)
        checkSum += ((unsigned char*)pBuff)[i];
    
    return( checkSum );
}